package com.yscz.peexcel.config;

import com.yscz.peexcel.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * 全局异常处理
 *
 * @author achen
 * @create 2021-08-13 18:48
 */
@ControllerAdvice
@ResponseBody
@Slf4j
public class GlobalExceptionHandler {


    /**
     * 统一异常处理@ExceptionHandler,主要用于Exception
     */
    @ExceptionHandler(Exception.class)
    public Result error(HttpServletRequest request, Exception e) {
        log.error("异常信息：", e);
        return Result.error(e.getMessage());
    }

}
